package cn.escco.ocr.controller;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import cn.escco.ocr.dto.vo.RespVo;
import cn.escco.ocr.enums.ErrorCode;

@RestControllerAdvice
public class BaseController {

    private static Logger logger = LoggerFactory.getLogger(BaseController.class);
    
    @ExceptionHandler({Exception.class})
    public RespVo<String> handleException(Exception e)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        logger.error(sw.toString());
        RespVo<String> result = new RespVo<>(ErrorCode.UNSUCCESSFUL);
        result.setMsg(e.getMessage());
        return result;
    }
}
